package com.meixun.xuanke.handle.activemq;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.meixun.xuanke.handle.model.MqCourseInfo;
import com.meixun.xuanke.handle.service.CourseService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 消息接受处理
 */
@Component
public class MessageAcceptance {
    Logger logger = LoggerFactory.getLogger(MessageAcceptance.class);
    @Resource
    CourseService courseService;


    /**
     * 选课操作
     * @param json
     */
    @JmsListener(destination = "mq.studentCourse")
    public void handleCourse(String json) {
        logger.info("选课或者退课处理："+json);
        MqCourseInfo mqCourseInfo=JSON.parseObject(json, new TypeReference<MqCourseInfo>() {});
        courseService.handleCourse(mqCourseInfo);
    }

    /**
     * 选课操作日志
     * @param json
     */
    @JmsListener(destination = "mq.addStuCourseRecord")
    public void addStuCourseRecord(String json) {
        MqCourseInfo mqCourseInfo=JSON.parseObject(json, new TypeReference<MqCourseInfo>() {});
        courseService.addStuCourseRecord(mqCourseInfo);
    }

}
